<template>

    <div>
        <router-link  :to="{name:'PatientInf',params:{pid:this.pid,rid:this.rid}}"><el-button type="primary" style="float: left;" >返回</el-button></router-link>
        <h3><center>个人病历</center></h3>
        <center>
            <div style="font-size: larger">
                <span >姓名：{{patient[0].name}}</span>
                <span v-if="patient[0].sex==1" style="margin-left: 50px">性别：男</span>
                <span v-if="patient[0].sex==2" style="margin-left: 50px">性别：女</span>
            </div>
        </center>
        <el-form  label-width="80px" class="login-box">
            <el-table
                    :data="case"
                    stripe
                    style="width: 100%">
                <el-table-column
                        prop="date"
                        label="日期"
                        width=""
                        align="center">
                </el-table-column>
                <el-table-column

                        label="主治医师"
                        width=""
                        align="center"
                >
                    <template #default="scope">
                        <p  v-for="doctor in doctors" >
                            <span v-if="scope.row.did==doctor.id">{{doctor.name}}</span>
                        </p>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="diagnose"
                        label="病因"
                        width=""
                >
                </el-table-column>

            </el-table>
            <el-button type="primary" style="float: right;" @click="OnSubmit" >打印病历</el-button>
        </el-form>
    </div>
</template>

<script>
    import {ElMessage} from "element-plus";
    import axios from "axios";

    export default {
        name: "DPatientCase",
        data(){
            return{
                rid:'',
                pid:'',
                patient: [{
                    deleted:0,
                    gmtCreate:'',
                    gmtUpdate:'',
                    id: '',
                    name: '',
                    idcard:'',
                    sex:'',
                    age:'',
                    login_name:'',
                    address:'',
                    password:'',
                    phone:'',
                }],
                case: [{
                    date: "",
                    diagnose: "",
                    did: "",
                    id: "",
                    pid: ""
                }],
                doctors: {
                    avatar:'',
                    deleted:0,
                    gmtCreate:'',
                    gmtUpdate:'',
                    id: '',
                    name: '',
                    info:'',
                    career:'',
                    level:'',
                    sex:'',
                    idCard:'',
                    password:'',
                    phone:'',
                    departmentId: '',
                },
                doctors:[]
            }

        },
        activated(){
            this.create();

        },
        methods:{
            create(){
                this.pid=localStorage.getItem('pid');
                axios.post("http://119.29.60.153:8001/doctorservice/patientcase/getCaseById/{id}?patientId="+this.pid).then(resp=> {
                    this.patient=resp.data.data.patient;
                    this.case=resp.data.data.case;
                })
                axios.get("http://119.29.60.153:8001/doctorservice/doctor/findAll").then(resp=> {
                    this.doctors = resp.data.data.items;
                })
            },
            OnSubmit(){
                ElMessage.success("打印成功，请到1号打印机领取")
            }
        }
    }
</script>

<style scoped>
    .login-box{
        margin: 20px auto;

    }
</style>